package ch.zhan.abjectivea.action_mode;

import ch.zhan.objectivea.R;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class ActionModeCouche implements Callback {

	private ActionModeCouchesListener mActionModeCouchesListener;
	private int position;
	public static final int MSG_ACTION_CHOICE_DELETE = 1;
	public static final int MSG_ACTION_CHOICE_EDIT = 2;

	public interface ActionModeCouchesListener {
		public void onActionModeCouchesChoice(int action, int position);
	}

	public ActionModeCouche(ActionModeCouchesListener listener, int position) {
		super();
		this.mActionModeCouchesListener = listener;
		this.position = position;
	}

	@Override
	public boolean onCreateActionMode(ActionMode mode, Menu menu) {
		MenuInflater inflater = mode.getMenuInflater();
		inflater.inflate(R.menu.context_menu, menu);

		return true;
	}

	@Override
	public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
		return false;
	}

	@Override
	public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
		switch (item.getItemId()) {
		case R.id.fragment_list_couche_delete:
			if(mActionModeCouchesListener!=null) mActionModeCouchesListener.onActionModeCouchesChoice(MSG_ACTION_CHOICE_DELETE,this.position);
			mode.finish();
			return true;
		case R.id.fragment_list_couche_edit:
			if(mActionModeCouchesListener!=null) mActionModeCouchesListener.onActionModeCouchesChoice(MSG_ACTION_CHOICE_EDIT,this.position);
			mode.finish();
			return true;
		default:
			mode.finish();
			return false;
		}
	}

	@Override
	public void onDestroyActionMode(ActionMode mode) {
	}
}
